package com.ruoyi.project.jiaqin.quotationclass.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.Ztree;
import com.ruoyi.framework.web.domain.ZtreeStr;
import com.ruoyi.project.system.dept.domain.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.jiaqin.quotationclass.mapper.QuotationClassMapper;
import com.ruoyi.project.jiaqin.quotationclass.domain.QuotationClass;
import com.ruoyi.project.jiaqin.quotationclass.service.IQuotationClassService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 行情类型管理Service业务层处理
 *
 * @author admin
 * @date 2020-12-21
 */
@Service
public class QuotationClassServiceImpl implements IQuotationClassService
{
    @Autowired
    private QuotationClassMapper quotationClassMapper;

    /**
     * 查询行情类型管理
     *
     * @param id 行情类型管理ID
     * @return 行情类型管理
     */
    @Override
    public QuotationClass selectQuotationClassById(String id)
    {
        return quotationClassMapper.selectQuotationClassById(id);
    }

    /**
     * 查询行情类型管理列表
     *
     * @param quotationClass 行情类型管理
     * @return 行情类型管理
     */
    @Override
    public List<QuotationClass> selectQuotationClassList(QuotationClass quotationClass)
    {
        return quotationClassMapper.selectQuotationClassList(quotationClass);
    }

    @Override
    public List<ZtreeStr> selectQuotationClassTree() {
        List<QuotationClass> list = quotationClassMapper.selectQuotationClassList(new QuotationClass());

        return initZtree(list);
    }

    @Override
    public List<QuotationClass> selectQuotationClassListByParentId(String parentId) {
        return quotationClassMapper.selectQuotationClassListByParentId(parentId);
    }

    /**
     * 新增行情类型管理
     *
     * @param quotationClass 行情类型管理
     * @return 结果
     */
    @Override
    public int insertQuotationClass(QuotationClass quotationClass)
    {
        quotationClass.setId(UUID.randomUUID().toString().replace("-",""));
        return quotationClassMapper.insertQuotationClass(quotationClass);
    }

    /**
     * 修改行情类型管理
     *
     * @param quotationClass 行情类型管理
     * @return 结果
     */
    @Override
    public int updateQuotationClass(QuotationClass quotationClass)
    {
        return quotationClassMapper.updateQuotationClass(quotationClass);
    }

    /**
     * 删除行情类型管理对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteQuotationClassByIds(String ids)
    {
        return quotationClassMapper.deleteQuotationClassByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除行情类型管理信息
     *
     * @param id 行情类型管理ID
     * @return 结果
     */
    @Override
    public int deleteQuotationClassById(String id)
    {
        return quotationClassMapper.deleteQuotationClassById(id);
    }

    @Override
    public List<ZtreeStr> initZtree(List<QuotationClass> qcList) {
        List<ZtreeStr> ztrees = new ArrayList<ZtreeStr>();
        for (QuotationClass qc : qcList) {
                ZtreeStr ztree = new ZtreeStr();
                ztree.setId(qc.getId());
                ztree.setpId(qc.getParentId());
                ztree.setName(qc.getName());
                ztree.setTitle(qc.getName());
                ztrees.add(ztree);
        }
        return ztrees;
    }

    @Override
    public List<QuotationClass> findSubQuotationIds(String classId) {
        return quotationClassMapper.findSubQuotationIds(classId);
    }
}
